<!DOCTYPE HTML>
<html lang="zh_CN">
<head><meta name="generator" content="Hexo 3.8.0">
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="cn華少">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <link rel="dns-prefetch" href="http://cnhuashao.com">
    <!--SEO-->

    <meta name="keywords" content="owncloud">


    <meta name="description" content="1、开启SSL模块
$ a2enmod ssl
2、启用SSL站点
$ a2ensite default-ssl

3、加入监听端口
$ sudo vim /etc/apache2/ports....">



<meta name="robots" content="all">
<meta name="google" content="all">
<meta name="googlebot" content="all">
<meta name="verify" content="all">

    <!--Title-->


<title>使用namecheap证书进行配置htmls安全访问 | cn華少</title>


    <link rel="alternate" href="/atom.xml" title="cn華少" type="application/atom+xml">


    <link rel="icon" href="/favicon/favicon.ico">

    



<link rel="stylesheet" href="/css/bootstrap.min.css?rev=3.3.7">
<link rel="stylesheet" href="/favicons.css">
<link rel="stylesheet" href="/css/style.css?rev=@@hash">




    
	<div class="hide">
		<script type="text/javascript">
			var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
		</script>
	</div>






    

</head>

</html>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<body>
    <header class="main-header" style="background-image:url(http://snippet.shenliyang.com/img/banner.jpg)">
    <div class="main-header-box">
        <a class="header-avatar" href="/" title="cn華少">
            <img src="/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
        </a>
        <div class="branding">
        	<!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
                <h2> 追梦，无惧 </h2>
            
    	</div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
                    <span class="sr-only"></span>
                        <i class="fa fa-bars"></i>
                    </span>
                    <a class="navbar-brand" href="http://cnhuashao.com">cn華少</a>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                            <li role="presentation" class="text-center">
                                <a href="/"><i class="fa "></i>首页</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/java/"><i class="fa "></i>Java</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/postgresql/"><i class="fa "></i>PostgreSQL</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/categories/工具/"><i class="fa "></i>工具</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/archives/"><i class="fa "></i>时间轴</a>
                            </li>
                        
                            <li role="presentation" class="text-center">
                                <a href="/about/"><i class="fa "></i>关于</a>
                            </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="使用namecheap证书进行配置htmls安全访问">
            
	            使用namecheap证书进行配置htmls安全访问
            
        </h1>
        <div class="post-meta">
    
        <span class="categories-meta fa-wrap">
            <i class="fa fa-folder-open-o"></i>
            <a class="category-link" href="/categories/owncloud/">owncloud</a>
        </span>
    

    
        <span class="fa-wrap">
            <i class="fa fa-tags"></i>
            <span class="tags-meta">
                
                    <a class="tag-link" href="/tags/owncloud/">owncloud</a>
                
            </span>
        </span>
    

    
        
        <span class="fa-wrap">
            <i class="fa fa-clock-o"></i>
            <span class="date-meta">2019/04/18</span>
        </span>
        
    
</div>
            
            
    </div>
    
    <div class="post-body post-content">
        <p>1、开启SSL模块</p>
<p>$ a2enmod ssl</p>
<p>2、启用SSL站点</p>
<p>$ a2ensite default-ssl</p>
<a id="more"></a>
<p>3、加入监听端口</p>
<p>$ sudo vim /etc/apache2/ports.conf</p>
<p>编辑Apache端口配置，加入443端口 (HTTPS采用的443端口传输数据)</p>
<p>　　Listen 443</p>
<p>4、配置虚拟主机</p>
<p>编辑default-ssl文件，加入证书对应的主机头。</p>
<p>$ sudo vim /etc/apache2/sites-enabled/default-ssl.conf</p>
<pre><code>ServerName extend.me
</code></pre><p>5、配置SSL证书</p>
<ul>
<li>按如下配置:</li>
</ul>
<p>　　SSLEngine on</p>
<p>　　SSLCertificateFile        /etc/apache2/ssl/ca.crt</p>
<p>　　SSLCertificateKeyFile   /etc/apache2/ssl/server.key</p>
<ul>
<li>重新启动Apache</li>
</ul>
<p>$ sudo service apache2 restart</p>
<p>SSLEngine on<br>SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem<br>SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key</p>
<p>编辑器打开.htaccess文件，写入如下规则：<br>RewriteEngine on<br>RewriteCond %{SERVER_PORT} !^443$<br>RewriteCond %{REQUEST_URI} !^/tz.php<br>RewriteRule (.*) https://%{SERVER_NAME}/$1 [R]</p>
<p>解释：<br>%{SERVER_PORT} —— 访问端口<br>%{REQUEST_URI} —— 比如如果url是 <a href="http://localhost/tz.php，则是指" target="_blank" rel="noopener">http://localhost/tz.php，则是指</a> /tz.php<br>%{SERVER_NAME} —— 比如如果url是 <a href="http://localhost/tz.php，则是指" target="_blank" rel="noopener">http://localhost/tz.php，则是指</a> localhost</p>
<p>以上规则的意思是，如果访问的url的端口不是443，且访问页面不是tz.php，则应用RewriteRule这条规则。这样便实现了：访问了 <a href="http://localhost/index.php" target="_blank" rel="noopener">http://localhost/index.php</a> 或者 <a href="http://localhost/admin/index.php" target="_blank" rel="noopener">http://localhost/admin/index.php</a> 等页面的时候会自动跳转到 <a href="https://localhost/index.php" target="_blank" rel="noopener">https://localhost/index.php</a> 或者 <a href="https://localhost/admin/index.php，但是访问" target="_blank" rel="noopener">https://localhost/admin/index.php，但是访问</a> <a href="http://localhost/tz.php" target="_blank" rel="noopener">http://localhost/tz.php</a> 的时候就不会做任何跳转，也就是说 <a href="http://localhost/tz.php" target="_blank" rel="noopener">http://localhost/tz.php</a> 和 <a href="https://localhost/tz.php" target="_blank" rel="noopener">https://localhost/tz.php</a> 两个地址都可以访问。</p>

    </div>
    
        <div class="reward" ontouchstart>
    <div class="reward-wrap">赏
        <div class="reward-box">
            
                <span class="reward-type">
                    <img class="alipay" src="/img/alipay.jpg"><b>支付宝打赏</b>
                </span>
            
            
                <span class="reward-type">
                    <img class="wechat" src="/img/wepay.jpg"><b>微信打赏</b>
                </span>
            
        </div>
    </div>
    <p class="reward-tip">赞赏是不耍流氓的鼓励</p>
</div>


    
    <div class="post-footer">
        <div>
            
                转载声明：商业转载请联系作者获得授权,非商业转载请注明出处 © <a href target="_blank">Snippet</a>
            
        </div>
        <div>
            
        </div>
    </div>
</article>

<div class="article-nav prev-next-wrap clearfix">
    
        <a href="/2019/04/18/owncloud-init/" class="pre-post btn btn-default" title="在ubuntu16.04上安装owncloud">
            <i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
            <span class="hidden-xs">在ubuntu16.04上安装owncloud</span>
        </a>
    
    
        <a href="/2019/04/18/Dropwizard-init/" class="next-post btn btn-default" title="使用Dropwizard搭建一个Hello World">
            <span class="hidden-lg">下一篇</span>
            <span class="hidden-xs">使用Dropwizard搭建一个Hello World</span><i class="fa fa-angle-right fa-fw"></i>
        </a>
    
</div>


    <div id="comments">
        
	
    <div id="vcomments" class="valine"></div>
    <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="/assets/valine.min.js"></script>

    <script>
        new Valine({
            av: AV,
            el: '#vcomments',
            appId: 'xOKV9J4UeQAtVkvnJC7Kq2Jn-gzGzoHsz',
            appKey: 'erIpQac4azoCmgfBB7Dl9maa',
            placeholder: '说点什么吧',
            notify: false,
            verify: false,
            avatar: 'mm',
            meta: 'nick,mail'.split(','),
            pageSize: '10',
            path: window.location.pathname,
            lang: 'zh_CN'.toLowerCase()
        })
    </script>


    </div>





                </main>
                
                    <aside id="article-toc" role="navigation" class="col-md-4">
    <div class="widget">
        <h3 class="title">Table of Contents</h3>
        
            <p>暂无目录</p>
        
    </div>
</aside>

                
            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>

<a id="back-to-top" class="icon-btn hide">
	<i class="fa fa-chevron-up"></i>
</a>




    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="busuanzi">
    
</div>

            </div>
            <div class="col-sm-12">
                <span>Copyright &copy; 2017
                </span> |
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> |
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>







<script src="/js/app.js?rev=@@hash"></script>

</body>
</html>